package com.ihighest.app.infox.myview;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ihighest.app.common.kit.SharedPreferencesKit;
import com.ihighest.app.common.kit.ToastKit;
import com.ihighest.app.infox.Const;
import com.ihighest.app.infox.R;
import com.ihighest.app.infox.activity.LoginActivity;
import com.ihighest.app.infox.activity.MyMassageActivity;
import com.ihighest.app.infox.activity.SearchActivity;

public class ActivityTitle extends RelativeLayout {
	public TextView top_title_text, rightText, messagenumber;
	public ImageView titleSearch, titleOther, titleRefresh, titleSetting, titleMsg, titleBack;
	public RelativeLayout rightLayout;
	Animation animation;

	@SuppressLint("NewApi")
	public ActivityTitle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
		super(context, attrs, defStyleAttr, defStyleRes);

	}

	public ActivityTitle(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
	}

	public ActivityTitle(final Context context, AttributeSet attrs) {
		super(context, attrs);
		if (isInEditMode()) {
			return;
		}
		View view = View.inflate(context, R.layout.infox_all_activity_title, this);
		rightLayout = (RelativeLayout) view.findViewById(R.id.infox_activityTitle_layout);
		top_title_text = (TextView) view.findViewById(R.id.top_title_text);
		// top_title_text.getPaint().setFakeBoldText(true);
		titleSearch = (ImageView) view.findViewById(R.id.infox_title_searchdata);
		titleRefresh = (ImageView) view.findViewById(R.id.infox_title_refreshData);
		titleSetting = (ImageView) view.findViewById(R.id.infox_activitytitle_setting);
		titleMsg = (ImageView) view.findViewById(R.id.infox_titleMsg);
		titleOther = (ImageView) view.findViewById(R.id.infox_title_other);
		titleBack = (ImageView) view.findViewById(R.id.infox_activitytitle_back);
		rightText = (TextView) view.findViewById(R.id.infox_activitytitle_rightText);
		messagenumber = (TextView) view.findViewById(R.id.id_number);

		animation = AnimationUtils.loadAnimation(context, R.anim.rotate);

		messagenumber.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(context, MyMassageActivity.class);
				intent.putExtra("title", "我的消息");
				messagenumber.setVisibility(View.GONE);								
				((Activity) context).startActivity(intent);
			}
		});

		titleMsg.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				if (TextUtils.isEmpty(SharedPreferencesKit.getString(context, Const.SP_KEY_USER_ID))) {
					Intent intent = new Intent(context, LoginActivity.class);
					ToastKit.showShort(context, Const.UN_LOGIN_ALERT);
					((Activity) context).startActivity(intent);
				} else {
					Intent intent = new Intent(context, MyMassageActivity.class);
					intent.putExtra("title", "我的消息");
					
					((Activity) context).startActivity(intent);
				}
			}
		});
		titleBack.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				((Activity) context).finish();
			}
		});

		titleSearch.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent(context, SearchActivity.class);
				((Activity) context).startActivity(intent);
			}
		});

		

	}

	

	public ActivityTitle(Context context) {
		super(context);
		if (isInEditMode()) {
			return;
		}
	}

	/**
	 * 设置最右侧图片
	 * 
	 * @param reshouse
	 */
	public void setOtherImg(int reshouse) {
		titleOther.setImageResource(reshouse);
	}

	/**
	 * 设置右侧第二个图片
	 * 
	 * @param barTitle
	 */
	public void setSecondImg(int reshouse) {
		titleSearch.setImageResource(reshouse);
	}

	/**
	 * 设置导航栏标题
	 * 
	 * @param barTitle
	 */
	public void setTitle(String barTitle) {
		top_title_text.setText(barTitle);
	}

	/**
	 * 设置右侧字体
	 * 
	 * @param barTitle
	 */
	public void setRightTextViewText(String string) {
		rightText.setText(string);
	}

	/**
	 * 设置导航栏标题颜色
	 * 
	 * @param barTitle
	 */
	public void setTitleColor(int barTitleColor) {

		top_title_text.setTextColor(barTitleColor);
	}

	/**
	 * 设置显示的控件
	 * 
	 * @param views
	 *            要显示的控件
	 * 
	 * @author lkx Created at 2015-10-3 上午10:54:15
	 */
	public void setViewVersible(View... views) {
		for (View view : views) {
			if (view != null) {
				view.setVisibility(View.VISIBLE);
			}
		}
	}

	/**
	 * 设置不显示的控件
	 * 
	 * @param views
	 *            不显示的控件
	 * 
	 * @author lkx Created at 2015-10-3 上午10:54:15
	 */
	public void setViewGone(View... views) {
		for (View view : views) {
			if (view != null) {
				view.setVisibility(View.GONE);
			}
		}
	}

	// public void refreshstart() {
	//
	// titleRefresh.setAnimation(animation);
	// animation.start();
	//
	// }
	//
	// public void refreshstop() {
	// animation.cancel();
	//
	// }

}
